﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpotItComponents;
using SpotItServerAPI;

namespace AppLayer
{
    public class TestDataGenerator
    {
        private Services services;
        private Session adminSession;

        public TestDataGenerator(Services services)
        {
            this.services = services;
        }

        public void GenerateData()
        {
            OperationResult result = services.accountManager.Login("admin", "admin");
            if (result.Success)
                adminSession = result.Data as Session;

            generateSymbolSets();
            generateDecks();

        }

        private void generateSymbolSets()
        {
            services.symbolManager.RemoveAllSymbolSets(adminSession);
            services.categoryManager.RemoveAllCategories(adminSession);

            SymbolSet ss1 = new SymbolSet("Classic SpotIt Images", false);
            SymbolSet ss2 = new SymbolSet("Fish", false);
            SymbolSet ss3 = new SymbolSet("Friends", false);
            SymbolSet ss4 = new SymbolSet("Math", false);
            SymbolSet ss5 = new SymbolSet("History", false);
            SymbolSet ss6 = new SymbolSet("Family", false);

            Category cat1 = new Category("SpotIt");
            Category cat2 = new Category("Animals");
            Category cat3 = new Category("People");
            Category cat4 = new Category("Education");

            services.categoryManager.Add(adminSession, cat1);
            services.categoryManager.Add(adminSession, cat2);
            services.categoryManager.Add(adminSession, cat3);
            services.categoryManager.Add(adminSession, cat4);


            ss1.AddCategory(cat1);
            ss2.AddCategory(cat2);
            ss3.AddCategory(cat3);
            ss4.AddCategory(cat4);
            ss5.AddCategory(cat4);
            ss6.AddCategory(cat3);

            services.symbolManager.Add(adminSession, ss1);
            services.symbolManager.Add(adminSession, ss2);
            services.symbolManager.Add(adminSession, ss3);
            services.symbolManager.Add(adminSession, ss4);
            services.symbolManager.Add(adminSession, ss5);
            services.symbolManager.Add(adminSession, ss6);

        }

        private void generateDecks()
        {
            Deck deck1 = new Deck("Best Deck", false);
            Deck deck2 = new Deck("Math Problems", false);
            Deck deck3 = new Deck("Family Faces", false);

            services.deckManager.RemoveAllDecks(adminSession);

            services.deckManager.Add(adminSession, deck1);
            services.deckManager.Add(adminSession, deck2);
            services.deckManager.Add(adminSession, deck3);

            List<Deck> decks;
            OperationResult result = services.deckManager.Lookup(adminSession, null, null, null);
                decks = result.Data as List<Deck>;
        }

    }
}
